﻿using System;
using System.ServiceModel;
using TfsRollUp.Core;

namespace TfsRollUp.Client
{
    /// <summary>
    /// Client interface for the Manager
    /// </summary>
    public class ManagerClient : IManager
    {
        private Lazy<IManager> _proxy = new Lazy<IManager>(() => 
        {
            EndpointAddress ep = new EndpointAddress(string.Format("{0}/{1}", Constants.URI, Constants.DefaultPipeName));
            return ChannelFactory<IManager>.CreateChannel(new NetNamedPipeBinding(), ep);
        });

        private IManager Proxy
        {
            get { return _proxy.Value; }
        }

        /// <summary>
        /// Enable or disable the processing of workitems
        /// </summary>
        /// <param name="enableProcessing">Enable or disable the rollup processing</param>
        public void EnableRollUpProcessing(bool enableProcessing)
        {
            Proxy.EnableRollUpProcessing(enableProcessing);
        }

        /// <summary>
        /// Enable or disable the creation of a DGML showing the workitem tree and their data/>
        /// </summary>
        /// <param name="workItemId">The workitem to monitor/create DGML diagram for. You'll typically want to monitor the root workitem.</param>
        /// <param name="enable"></param>
        /// <returns></returns>
        public int MonitorWorkItem(int workItemId, bool enable)
        {
            return Proxy.MonitorWorkItem(workItemId, enable);
        }
    }
}
